package com.heifeng.cloudshelf.mvp.product.activity;

import android.content.Context;
import android.os.Handler;
import androidx.appcompat.app.AppCompatActivity;

import android.text.TextUtils;
import android.view.View;
import android.view.animation.AnimationUtils;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.heifeng.cloudshelf.R;
import com.heifeng.cloudshelf.base.BaseActivity;
import com.heifeng.cloudshelf.mvp.product.contract.ProductActivityContract;
import com.heifeng.cloudshelf.mvp.product.presenter.ProductActivityPresenter;
import com.heifeng.cloudshelf.mvp.programme.activity.ProgrammeActivity;
import com.heifeng.cloudshelf.utils.IntentUtil;

import butterknife.BindView;
import butterknife.OnClick;

/*
*产品大全
 */
public class ProductActivity extends BaseActivity<ProductActivityPresenter> implements ProductActivityContract.View {
    @BindView(R.id.l_wholehome)
    LinearLayout lWholehome;

    @BindView(R.id.l_cupboards)
    LinearLayout lCupboards;

    @BindView(R.id.l_wodeendoors)
    LinearLayout lWodeendoors;

    @BindView(R.id.l_finishedprod)
    LinearLayout lFinishedprod;

    @BindView(R.id.iv_image)
    ImageView iv_image;

    private TranslateAnimation translateAnimation;

    public static void open(Context context) {
        IntentUtil.startActivity(context, ProductActivity.class);
    }

    @Override
    protected int getLayout() {
        return R.layout.activity_product;
    }

    @Override
    protected void initEventAndData() {
        onStartAnim();

        mPresenter.toGetAllProduct();
    }

    @Override
    protected void initInject() {
        getActivityComponent().inject(this);
    }

    public void onStartAnim() {
        lWholehome.setVisibility(View.INVISIBLE);
        lCupboards.setVisibility(View.INVISIBLE);
        lWodeendoors.setVisibility(View.INVISIBLE);
        lFinishedprod.setVisibility(View.INVISIBLE);

        translateAnimation = (TranslateAnimation) AnimationUtils.loadAnimation(ProductActivity.this, R.anim.anim_prduct1);

        if (lWholehome != null) {
            lWholehome.setVisibility(View.VISIBLE);
            lWholehome.startAnimation(translateAnimation);
        }

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                if (lCupboards != null) {
                    lCupboards.setVisibility(View.VISIBLE);
                    lCupboards.startAnimation(translateAnimation);
                }
            }
        }, 500);    //延时

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                if (lWodeendoors != null) {
                    lWodeendoors.setVisibility(View.VISIBLE);
                    lWodeendoors.startAnimation(translateAnimation);
                }
            }
        }, 1000);    //延时

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                if (lFinishedprod != null) {
                    lFinishedprod.setVisibility(View.VISIBLE);
                    lFinishedprod.startAnimation(translateAnimation);
                }
            }
        }, 1500);    //延时
    }

    @OnClick({R.id.l_wholehome, R.id.l_cupboards, R.id.l_wodeendoors, R.id.l_finishedprod, R.id.l_back})
    public void Onclick(View view) {


        switch (view.getId()) {
            case R.id.l_wholehome://全屋定制
                if (!mPresenter.isInitTemplateId()) {
                    return;
                }
                ProgrammeActivity.StartActivity(ProductActivity.this, R.mipmap.ic_title_products, "产品大全 > 全屋定制", 1,mPresenter.getTemplateId("全屋定制"));
                break;
            case R.id.l_cupboards://橱柜定制
                if (!mPresenter.isInitTemplateId()) {
                    return;
                }
                ProgrammeActivity.StartActivity(ProductActivity.this, R.mipmap.ic_title_products, "产品大全 > 橱柜定制", 2,mPresenter.getTemplateId("橱柜定制"));
                break;
            case R.id.l_wodeendoors://木门定制
                if (!mPresenter.isInitTemplateId()) {
                    return;
                }
                ProgrammeActivity.StartActivity(ProductActivity.this, R.mipmap.ic_title_products, "产品大全 > 木门定制", 3,mPresenter.getTemplateId("木门定制"));
                break;
            case R.id.l_finishedprod://成品宅配
                if (!mPresenter.isInitTemplateId()) {
                    return;
                }
                ProgrammeActivity.StartActivity(ProductActivity.this, R.mipmap.ic_title_products, "产品大全 > 成品宅配", 4,mPresenter.getTemplateId("成品宅配"));
                break;
            case R.id.l_back:
                finish();
                break;
        }
    }

    @Override
    public void setWeiXinImage(String url) {
        if (!TextUtils.isEmpty(url)) {
            Glide.with(this).load(url).apply(new RequestOptions().error(R.mipmap.ic_wxacode)).into(iv_image);
        }
    }

    @Override
    public void startView() {

    }
}
